<?

define('PAYPAL_MERCHANT_EMAIL', 'd.karabut@gmail.com');
define('PAYPAL_ITEM_NAME', 'RenewableDigest.com Advertisement');
define('PAYPAL_ITEM_PRICE', '10.00');
define('PAYPAL_SERVER', 'sandbox');
define('SITE_URL', $_SERVER['HTTP_HOST']);

$content_item_id = '112';

$params = array(
    'server'=>PAYPAL_SERVER,
	'cmd'=>'_xclick',
	'business'=>PAYPAL_MERCHANT_EMAIL,
	'item_name'=>PAYPAL_ITEM_NAME,
	'item_number'=>$content_item_id,
	'return'=>SITE_URL.'/browse/view/id/'.$content_item_id.'/payed',  // need to handle 'payed' parameter in item's view - message should be displayed
	'notify_url'=>SITE_URL.'/ipn_handler.php',
	'amount'=>PAYPAL_ITEM_PRICE);

$button = createButton($params);

function createButton($params) {
	if (!$params) {
		return "Params array is empty";
	}
	
	$form = '<form action="https://'.$params['server'].'.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="'.$params['cmd'].'">
        <input type="hidden" name="business" value="'.$params['business'].'">';
	foreach ($params as $name=>$val) {
		if (!in_array($name, array('server','cmd','business'))) {
			$form .= '<input type="hidden" name="'.$name.'" value="'.$val.'">';
		}
	}
        
	$form .= '<input type="image" name="submit" border="0"
342          src="https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif"
        alt="PayPal - The safer, easier way to pay online">
</form>';
	
	return $form;

}